package com.example.conference.controller;

import com.example.conference.domain.CourseStudent;
import com.example.conference.domain.CourseTeacher;
import com.example.conference.domain.User;
import com.example.conference.domain.dto.PageParam;
import com.example.conference.service.CourseStudentServiceImpl;
import com.example.conference.service.CourseTeacherServiceImpl;
import com.example.conference.service.UserServiceImpl;
import com.example.conference.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(originPatterns = "*",allowCredentials = "true")
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    CourseTeacherServiceImpl courseTeacherService;
    @Autowired
    CourseStudentServiceImpl courseStudentService;
    @Autowired
    UserServiceImpl userService;

    //教师查询自己开的课程
    @RequestMapping("/queryCourse/{teacherId}")
    public Result queryCourse(@RequestBody PageParam page,@PathVariable("teacherId") Integer tId){
        return courseTeacherService.queryCourseByTeacher(page, tId);}

    //教师查询自己开的课程的学生信息（分数）
    @RequestMapping("/queryStudentInfo/{ctId}")
    public Result queryStudentInfo(@RequestBody PageParam page, @PathVariable("ctId") Integer ctId){
        return courseStudentService.queryStudentInfo(page,ctId);}

    //给学生打分
    @RequestMapping("/scoringStudent")
    public Result scoringStudent(@RequestBody CourseStudent courseStudent){
        courseStudentService.update(courseStudent);
        return Result.success();
    }

    //教师开课
    @RequestMapping("/addCourse")
    public Result addCourseTeacher(@RequestBody CourseTeacher courseTeacher){
        return courseTeacherService.addCourseTeacher(courseTeacher);}

    @RequestMapping("/deleteCourse/{id}")
    public Result deleteCourse(@PathVariable Integer id){
        return courseTeacherService.deleteCourseTeacher(id);}

    @ExceptionHandler
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }
}